package com.leoman.plz_p.adapter;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;

import com.leoman.plz_p.R;
import com.leoman.plz_p.module.bean.MissionDetailBean;

import cn.com.corelib.utils.adapter.BaseAdapterHelper;
import cn.com.corelib.utils.adapter.normal.QuickAdapter;

/**
 * Created by guoh on 2018/7/9.
 */
public class MissionClassAdapter extends QuickAdapter<MissionDetailBean> {


    public MissionClassAdapter(Context context) {
        super(context, R.layout.item_mission_class);
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, final MissionDetailBean item, final int position) {

        switch (item.getStatus()){
            case 1:
                helper.setBackgroundRes(R.id.iv_class_progress,R.mipmap.icon_zero_to_four);
                break;
            case 2:
                helper.setBackgroundRes(R.id.iv_class_progress,R.mipmap.icon_one_to_one);
                break;
        }

        helper.getView(R.id.iv_project_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                item.isShow=(!item.isShow);
                notifyDataSetChanged();
            }
        });
        if (item.isShow){
            helper.setVisible(R.id.ls_point,true);
        }else {
            helper.setVisible(R.id.ls_point,false);
        }
        if (helper.getView(R.id.ls_point).getVisibility()==View.VISIBLE){
            helper.setBackgroundRes(R.id.iv_project_open,R.mipmap.icon_up_gary);
        }else {
            helper.setBackgroundRes(R.id.iv_project_open,R.mipmap.icon_down_gary);
        }

        helper.setText(R.id.tv_class_name,item.getName());
        helper.setText(R.id.tv_class_status,item.getStatus()==1?"未完成":"已完成");
        MissionPointAdapter adapter=new MissionPointAdapter(context);
        adapter.replaceAll(item.getLists());
        helper.setAdapter(R.id.ls_point,adapter);
        helper.setOnItemClickListener(R.id.ls_point, new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
                switch (pos){
                    case 0:
                        if (onItemClick!=null){
                            onItemClick.onVideoClick(position,pos);
                        }
                        break;
                    case 1:
                        if (onItemClick!=null){
                            onItemClick.onTestClick(position,pos);
                        }
                        break;
                }
            }
        });
    }
    public void setOnItemClick(onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    private onItemClick onItemClick;

    public interface onItemClick{
        void onVideoClick(int parentPosition, int position);
        void onTestClick(int parentPosition, int position);
    }
}
